import {API_BASE_URL} from '@/config/setting';
import axios from 'axios';
import request from '@/utils/request';
import {message} from 'ant-design-vue';
import {getToken,setToken} from './token-util';

export function downloadFn(data) {
	axios({
		method: 'post',
		url: API_BASE_URL + data.url,
		responseType: 'blob',
		headers: {
			Authorization: getToken()
		},
		timeout: 8000,
		data: data.params
	})
	.then((res) => {
		console.log("res", res);
		const link = document.createElement('a');
		const blob = new Blob([res.data], {
			type: 'application/vnd.ms-excel'
		});
		link.style.display = 'none';
		link.href = URL.createObjectURL(blob);

		// link.download = res.headers['content-disposition'] //下载后文件名
		link.download = data.filename; //下载的文件名
		document.body.appendChild(link);
		link.click();
		document.body.removeChild(link);
		message.success('操作成功！');
	})
	.catch((error) => {
		message.error('参数错误！')
	})
}
